.386
.model flat, stdcall
option casemap :none

	include	\masm32\include\windows.inc
	include \masm32\include\kernel32.inc
	include \masm32\include\user32.inc
	include \masm32\include\gdi32.inc

	includelib \masm32\lib\kernel32.lib
	includelib \masm32\lib\user32.lib
	includelib \masm32\lib\gdi32.lib
	
	MainProc	proto :DWORD, :DWORD, :DWORD, :DWORD

.data
	szAppName		db "Test layered dialog", 0
	szConfirm		db "Are You really want to exit?", 0
	
.data?
	hInstance	HINSTANCE ?
	CommandLine	LPSTR ?
	
.const
	ID_DLG1	equ 1001
	IDC1	equ 1002
	IDC2	equ 1003
	IDC3	equ 1004
	
.code
start:
	invoke	GetModuleHandle, NULL
	mov	hInstance, eax
	invoke	GetCommandLine
	mov	CommandLine, eax
	invoke DialogBoxParam, hInstance, ID_DLG1, 0, addr MainProc, 0
	invoke	ExitProcess, eax
	
MainProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
	.if uMsg == WM_INITDIALOG
	.elseif uMsg == WM_COMMAND
		mov eax,wParam
		shr eax,16
		.if wParam == 1002
			; Установить бит прозрачности (WS_EX_LAYERED) расширенного стиля окна
			invoke GetWindowLong,hWnd, GWL_EXSTYLE
			or eax, WS_EX_LAYERED
			invoke SetWindowLong, hWnd, GWL_EXSTYLE, eax
			; Установить значение альфа канала в значение 70%
			invoke SetLayeredWindowAttributes, hWnd, 0, (255 * 70) / 100, LWA_ALPHA
		.elseif wParam == 1003
			; Удалить бит WS_EX_LAYERED расширенного стиля окна
			invoke GetWindowLong,hWnd, GWL_EXSTYLE
			mov ecx, WS_EX_LAYERED
			not ecx
			and eax, ecx 
			invoke SetWindowLong, hWnd, GWL_EXSTYLE, eax
			; Послать окну и его дочерним окнам указание на перерисовку
			invoke RedrawWindow,hWnd, NULL, NULL, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN
		.elseif wParam == 1004
			invoke MessageBox, hWnd, addr szConfirm, addr szAppName,MB_YESNOCANCEL
			.if eax == IDYES
				invoke SendMessage, hWnd, WM_CLOSE, 0, 0
			.endif
		.endif
	.elseif uMsg == WM_CLOSE
		invoke EndDialog,hWnd,0
		ret
	.endif
	xor eax, eax	
	ret
MainProc endp

end start
